﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/// <summary>
/// Summary description for ShoppingCart
/// </summary>
public class ShoppingCart
{

    public static List<CartItem> allCart = new List<CartItem>();
    public ShoppingCart()
    {
        //allCart = 
    }
    public static void addCart(product p)
    {
        bool ex = false;
        foreach (CartItem ci in allCart)
        {
            if (ci.pro.Equals(p))
            {
                ci.quantity++;
                ex = true;
                break;
            }
        }
        if(!ex){
            CartItem ci = new CartItem(p);
            allCart.Add(ci);
        }

    }
    public static void removeCart(product p)
    {
        CartItem ci = allCart.First(c => c.pro.Equals(p));
        if (ci != null)
        {
            if (ci.quantity > 1)
                ci.quantity--;
            else allCart.Remove(ci);
        }

    }
}